/*
 * TTSCaller.h
 *
 *  Created on: 2012-9-10
 *      Author: liangrongtang
 */

#ifndef TTSCALLER_H_
#define TTSCALLER_H_

#include "Common.h"
#include "TTSDataGram.h"
#include "TTSParams.h"
#include "TTSText2AudioReq.h"
#include <string>

class TTSCaller
{
    private:
        std::string _text;

        LAN _lan;

        ENCODING _encoding;

        std::string _ttsSvrIP;

        uint16 _ttsSvrPort;

        bool Connect(int fd);

        TTSDataGram* ReadTTSDatagram(int fd);

        bool IsValidConnAns(const TTSDataGram* datagram);

        TTSParams* MakeTTSParams(LAN lan, ENCODING encoding);

        bool IsValidSetParamsAns(const TTSDataGram* datagram);

        TTSText2AudioReq* MakeText2AudioReq(const char* text);

        int RecvAudio(int fd, Item* item);

        void Reformat(Item* item, uint32 bitsPerSample);

        void AddWavHeader(Item* item, uint32 bitsPerSample, uint32 sampleRate, uint32 dataLen);

    public:
        TTSCaller()
            : _lan(ZH), _encoding(GBK)
            , _ttsSvrIP("10.81.16.15"), _ttsSvrPort(1000)
        { }

        ~TTSCaller()
        { }

        void SetTTSReq(std::string text, LAN lan, ENCODING encoding);

        int TalkWithTTS(Item* item);
};


#endif /* TTSCALLER_H_ */
